package com.config.db;



import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;
import java.util.Properties;

/**
 * Created by Administrator on 2017/8/9.
 */
//@Configuration
//@EnableTransactionManagement
public class DBConfiguration {
//    @Value("${spring.datasource.mysql.url}")
//    String url;
//    @Value("${spring.datasource.mysql.driverClassName}")
//    String driver;
//    @Value("${spring.datasource.mysql.username}")
//    String userName;
//    @Value("${spring.datasource.mysql.password}")
//    String password;
//
//    @Bean(name = "masterDataSource")
//    @Primary
//    public DataSource dataSource() {
//        DriverManagerDataSource dataSource = new DriverManagerDataSource();
//        dataSource.setDriverClassName(driver);
//        dataSource.setUrl(url);
//        dataSource.setUsername(userName);
//        dataSource.setPassword(password);
//        return dataSource;
//    }
//
//    @Bean(name = "masterSessionFactory")
//    @Primary
//    public LocalSessionFactoryBean sessionFactory(@Qualifier("masterDataSource") DataSource dataSource) {
//        LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
//        sessionFactory.setDataSource(dataSource);
//        sessionFactory.setPackagesToScan("com.models");
//        Properties hibernateProperties = new Properties();
//        hibernateProperties.put("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
//        hibernateProperties.put("hibernate.show_sql", "false");
//        hibernateProperties.put("hibernate.hbm2ddl.auto", "update");
//        hibernateProperties.put("hibernate.naming.implicit-strategy", "org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl");
//        hibernateProperties.put("hibernate.naming.physical-strategy", "org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl");
//        sessionFactory.setHibernateProperties(hibernateProperties);
//        return sessionFactory;
//    }
//
//    @Bean(name = "masterTransactionManager")
//    @Primary
//    public HibernateTransactionManager masterTransactionManager(@Qualifier("masterSessionFactory") SessionFactory sessionFactory) {
//        HibernateTransactionManager transactionManager = new HibernateTransactionManager();
//        transactionManager.setSessionFactory(sessionFactory);
//        return transactionManager;
//    }
}